package com.squirrel.serialportcore.machine.init.before;

import com.squirrel.serialportcore.common.CommonBase;
import com.squirrel.serialportcore.entity.mapper.PortQueueMapper;
import com.squirrel.serialportcore.entity.property.JsonProperty;
import com.squirrel.serialportcore.machine.creator.NameRuleCreator;

/**
 * 名称服务初始化
 * 需要在Spring初始化之前 在CommPortInit之后
 *
 * @author Squbi
 * @date 2021/3/23 10:41
 */
public class NameInitializer {
    private NameInitializer() {
    }

    public static void initName() {
        JsonProperty jsonProperty = CommonBase.getJsonProperty();
        NameRuleCreator nameRuleCreator = new NameRuleCreator(jsonProperty.getAppName());
        for (String portName : jsonProperty.getPortProperty().keySet()) {
            PortQueueMapper portQueueMapper = nameRuleCreator.creatName(portName);
            CommonBase.getPortQueueName().put(portName, portQueueMapper);
        }
    }
}
